package E_2024;


/*
    题目描述
        公司用一个字符串来表示员工的出勤信息
        absent：缺勤
        late：迟到
        leaveearly：早退
        present：正常上班
        现需根据员工出勤信息，判断本次是否能获得出勤奖，能获得出勤奖的条件如下：
            缺勤不超过一次；
            没有连续的迟到/早退；
            任意连续7次考勤，缺勤/迟到/早退不超过3次。
    输入描述
        用户的考勤数据字符串
        记录条数 >= 1；
        输入字符串长度 < 10000；
        不存在非法输入；
        如：
        2
        present
        present absent present present leaveearly present absent
 */
public class E_100_19 {
    public static void main(String[] args) {
        System.out.println(ans("present absent present present leaveearly present absent present"));
        System.out.println(ans("present absent present present leaveearly present late present"));
        System.out.println(ans("present absent late present leaveearly present absent"));
        System.out.println(ans("present absent late present leaveearly present late"));
        System.out.println(ans("present absent present present leaveearly present late"));
        System.out.println(ans("present absent present late leaveearly present absent"));
    }
    public static boolean ans(String str){
        int err = 0;
        int ll = 0;
        int abs = 0;
        String[] split = str.split(" ");
        for (int i = 0, j = 0; i < split.length && j < split.length; j++) {
            if (j - i == 7) {
                String tempI = split[i];
                // 统计7次内的考勤，超出的计数-1
                switch (tempI) {
                    case "absent", "late", "leaveearly" -> err--;
                }
                i++;
            }
            String tempJ = split[j];
            // 统计考勤次数
            switch (tempJ) {
                case "absent" -> {
                    abs++;
                    err++;
                    ll = 0;
                }
                case "late", "leaveearly" -> {
                    ll++;
                    err++;
                }
                case "present" -> ll = 0;
            }
            if (abs > 1) return false;
            if (err > 3) return false;
            if (ll > 1) return false;
        }
        return true;
    }
}
